package org.example.eight3.util;

import org.example.eight3.model.User;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class DBUtil {
    private static final Properties props;
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            props = new Properties();
            InputStream resource = DBUtil.class
                    .getClassLoader()
                    .getResourceAsStream("db.properties");
            props.load(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public static Connection getConn() {

        try {
            return DriverManager.getConnection(
                    props.getProperty("jdbcUrl"),
                    props.getProperty("username"),
                    props.getProperty("password")
            );
        }  catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}